import { pageDialog } from '@/components/page-dialog';
import { ref } from 'vue';
export function usePageDialog(createFn?: () => void, editFn?: () => void) {
  const defaultConfig = ref<any>({});
  const editValue = ref<any>({});
  const pageDialogRef = ref<InstanceType<typeof pageDialog>>();
  const newClick = () => {
    pageDialogRef.value.dialogVisible = true;
    for (const item in editValue.value) {
      defaultConfig.value[`${item}`] = '';
    }
    createFn && createFn();
  };
  const editClick = (value: any) => {
    pageDialogRef.value.dialogVisible = true;
    editValue.value = value;
    for (const item in value) {
      defaultConfig.value[`${item}`] = value[item];
    }
    editFn && editFn();
  };

  return { pageDialogRef, newClick, editClick, defaultConfig };
}
